/**
 * Advanced Software Engineering (monica Farrow)
 * JUnit VariousMethodsTest class
 * 
 * Some of the methods in this class have been based on lecture notes provided by
 * Monica Farrow as a part of Software Engineering courses at Heriot-Watt University.
 */

package depotTests;

import static org.junit.Assert.*;

import org.junit.Test;
import depot.*;
import depotModels.*;
import depotAdmin.DuplicateIDException;

public class VariousMethodsTest {

	private int[] dim1;
	private Parcel pcl;
	private CustomerQueue cq;
	private ParcelUncollected pu;
	private String inputLine;

	/**
	 * STAGE 1
	 * Test some methods in CustomerQueue
	 */
	
	/**
	 * getCustomerByID -  test for return of null or Customer
	 * @throws DuplicateIDException 
	 * @throws IllegalArgumentException 
	 * @throws ArrayIndexOutOfBoundsException 
	 */
	@Test
	public final void testGetCustByID() throws ArrayIndexOutOfBoundsException, IllegalArgumentException, DuplicateIDException {

		// create CustomerQueue object to access getCustomerByID
		// and create empty custQueue
		cq = new CustomerQueue();

		// Test 1 - ID doesn't match Customer object in custQueue
		Customer expected1 = null;
		String message1 = "Failed for ID 000501";
		Customer actual1 = cq.getCustomerByID("000501");
		assertEquals(message1, expected1, actual1);

		// Test 2 - ID does match Customer object in custQueue
		// create Parcel, Customer, and add to custQueue
		dim1 = new int[] {25,25,45};
		pcl = new Parcel("E000112", dim1, 2.55, 1);
		inputLine = "000501,Gregor,McCloud,E000112";
		cq.processLine(pcl,inputLine, 1);
		
		String expected2 = "000501";
		String message2 = "Failed for ID 000501";
		String actual2 = cq.getCustomerByID("000501").getCustID();
		assertEquals(message2, expected2, actual2);
	}

	/**
	 * removeFromQueue -  test for return of true or false
	 * @throws DuplicateIDException 
	 * @throws IllegalArgumentException 
	 * @throws ArrayIndexOutOfBoundsException 
	 */
	@Test
	public final void testRemoveFromQueue() throws ArrayIndexOutOfBoundsException, IllegalArgumentException, DuplicateIDException {

		// create CustomerQueue object to access removeFromQueue
		// and create empty custQueue
		// and create Customer object to try to remove from custQueue
		cq = new CustomerQueue();
		dim1 = new int[] {25,25,45};
		pcl = new Parcel("E000112", dim1, 2.55, 1);
		Customer cust1 = new Customer("000501","Gregor","McCloud",pcl);

		// Test 1 - no Customer object in custQueue
		Boolean expected1 = false;
		String message1 = "Failed for empty custQueue";
		Boolean actual1 = cq.removeFromQueue(cust1,false);
		assertEquals(message1, expected1, actual1);

		// Test 2 - 1 Customer object in custQueue
		// create Customer, add to custQueue,
		// then retrieve for use with removeFromQueue
		dim1 = new int[] {25,25,45};
		pcl = new Parcel("E000112", dim1, 2.55, 1);
		inputLine = "000501,Gregor,McCloud,E000112";
		cq.processLine(pcl,inputLine, 1);
		Customer cust2 = cq.getCustomerByID("000501");
		
		Boolean expected2 = true;
		String message2 = "Failed for Customer 000501";
		Boolean actual2 = cq.removeFromQueue(cust2,false);
		assertEquals(message2, expected2, actual2);
	}


	/**
	 * STAGE 2
	 * Test some methods in ParcelUncollected
	 */
	
	/**
	 * getParcelByID -  test for return of null or Parcel
	 * @throws DuplicateIDException 
	 * @throws IllegalArgumentException 
	 * @throws ArrayIndexOutOfBoundsException 
	 */
	@Test
	public final void testGetPclByID() throws ArrayIndexOutOfBoundsException, IllegalArgumentException, DuplicateIDException {

		// create ParcelUncollected object to access getParcelByID
		// and create empty parcelList
		pu = new ParcelUncollected();

		// Test 1 - ID doesn't match Parcel object in parcelList
		Parcel expected1 = null;
		String message1 = "Failed for ID E000112";
		Parcel actual1 = pu.getParcelByID("E000112","dupCheck");
		assertEquals(message1, expected1, actual1);

		// Test 2 - ID does match Parcel object in parcelList
		// create Parcel, and add to parcelList
		inputLine = "E000100,20,30,40,2.6,6";
		pu.processLine(inputLine, 1);
		
		String expected2 = "E000100";
		String message2 = "Failed for ID E000100";
		String actual2 = pu.getParcelByID("E000100","dupCheck").getParcelID();
		assertEquals(message2, expected2, actual2);
	}

	/**
	 * removeParcel -  test for return of true or false
	 * @throws DuplicateIDException 
	 * @throws IllegalArgumentException 
	 * @throws ArrayIndexOutOfBoundsException 
	 */
	@Test
	public final void testRemoveParcel() throws ArrayIndexOutOfBoundsException, IllegalArgumentException, DuplicateIDException {

		// create ParcelUncollected object to access removeParcel
		// and create empty parcelList
		// and create Parcel object to try to remove from parcelList
		pu = new ParcelUncollected();

		// Test 1 - no Parcel object in parcelList
		Boolean expected1 = false;
		String message1 = "Failed for empty parcelList";
		Boolean actual1 = pu.removeParcel("E000112");
		assertEquals(message1, expected1, actual1);

		// Test 2 - 1 Parcel object in parcelList
		// create Parcel, add to parcelList,
		inputLine = "E000100,20,30,40,2.6,6";
		pu.processLine(inputLine, 1);
		
		Boolean expected2 = true;
		String message2 = "Failed for Parcel E000100";
		Boolean actual2 = pu.removeParcel("E000100");
		assertEquals(message2, expected2, actual2);
	} 


	/**
	 * STAGE 3
	 * Test toString methods in Customer & Parcel
	 */
	
	/**
	 * Customer toString
	 */
	@Test
	public final void testCustToString() {

		// create Customer object
		dim1 = new int[] {30,30,30};
		pcl = new Parcel("E000112", dim1, 2.55, 2);
		Customer cust = new Customer("000501","Gregor","McCloud",pcl);

		String expected1 = "ID: 000501,  Name: Gregor McCloud,  ParcelID: E000112";
		String message1 = "Failed for Customer toString";
		String actual1 = cust.toString();
		assertEquals(message1, expected1, actual1);
	}


	/**
	 * Parcel toString
	 */
	@Test
	public final void testPclToString() {

		// create Parcel object
		dim1 = new int[] {30,30,30};
		pcl = new Parcel("E000112", dim1, 2.55, 2);

		String expected1 = "ID: E000112,  Dimensions: 30*30*30, Weight: 2.55,  Days: 2";
		String message1 = "Failed for Parcel toString";
		String actual1 = pcl.toString();
		assertEquals(message1, expected1, actual1);
	}




}
